package com.lhkj.ct.meta.modules.gauge.validation;

import com.lhkj.ct.base.validator.group.ValGroups;
import com.lhkj.ct.meta.modules.gauge.model.entity.TblScale;
import org.hibernate.validator.spi.group.DefaultGroupSequenceProvider;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 *     题目校验
 * </p>
 */
public class ScaleGroupSequenceProvider implements DefaultGroupSequenceProvider<TblScale> {

    @Override
    public List<Class<?>> getValidationGroups(TblScale scale) {
        List<Class<?>> defaultGroupSequence = new ArrayList<>();
        // warn 这一步不能省,否则Default分组都不会执行，会抛错
        defaultGroupSequence.add(TblScale.class);
        defaultGroupSequence.add(ValGroups.Insert.class);
        defaultGroupSequence.add(ValGroups.Update.class);
        if (scale != null) {
            // 单选和多选必须设置选项
            if (Objects.equals(scale.getRecommend(), Boolean.TRUE)) {
                defaultGroupSequence.add(TblScale.recommend.class);
            }
        }
        return defaultGroupSequence;
    }
}
